<?php
$v_recordtype = "";
$v_reporttype_filter = "";
if(isset($_REQUEST['hdn_recordtype_filter'])){
	$v_reporttype_filter = $_REQUEST['hdn_recordtype_filter'];
}
$v_recordtype = $_SESSION['onegate_current_recordtype'];
//$v_recordtype = $v_reporttype_filter;

if(isset($_REQUEST['hdn_record_number_page'])&&$_REQUEST['hdn_record_number_page']!=""){
	$v_limit_row = $_REQUEST['hdn_record_number_page'];
	//$_SESSION['v_session_limit_num_page'] = $v_limit_row;
}

$v_page = 1;
//session_start();
//$_SESSION['v_session_page'] = $v_page;
if(isset($_REQUEST['hdn_page'])&&$_REQUEST['hdn_page']!=""){
	$v_page=$_REQUEST['hdn_page'];	
	//$_SESSION['v_session_page'] = $v_page;
}

//Lay du lieu tu database
if ($v_reporttype_id > 0){
	$v_xml_str = $arr_single_record['C_RECEIVED_RECORD_XML_DATA'];
}else{
	$v_appointed_date = "";
	$v_xml_str = '<?xml version="1.0" encoding="UTF-8"?><root><data_list></data_list></root>';
}
//$v_undo_xml_file = "../xml/report/so_tiep_nhan_ho_so.xml";
$v_undo_xml_file = "tim_kiem_ho_so.xml";
$v_undo_xml_file = "../xml/undo/".$v_reporttype_filter.'_'.$v_undo_xml_file;
if (!is_file($v_undo_xml_file)){
	$v_undo_xml_file = "../xml/undo/tim_kiem_ho_so.xml";
}
$v_report_xml_string = _read_file($v_undo_xml_file);
$table_struct_rax = new RAX(); 
$table_struct_rec = new RAX(); 
$table_struct_rax->open($v_report_xml_string);
$table_struct_rax->record_delim = 'table_struct_of_filter_form';
$table_struct_rax->parse();
$table_struct_rec = $table_struct_rax->readRecord(); 
$table_struct_row = $table_struct_rec->getRow();
$v_form_title = $table_struct_row["form_title"];
$v_first_col_width = $table_struct_row["first_col_width"];
$v_second_col_width = (100-$v_first_col_width)."%";

///Begin//Form
$v_html_string = '';
//Begin//Bang chua cac thanh phan cua form
$v_html_string = $v_html_string . "<form action='index.php' method='post' name='f_dsp_single_conditions'>";
$v_html_string = $v_html_string . "<table width='100%'  border='0' cellspacing='0' cellpadding='0'><tr>";
$v_html_string = $v_html_string . "<td class='large_title'>".$v_form_title."</td>";
$v_html_string = $v_html_string . "</tr></table>";
//Bang chua cac bin hidden
$v_html_string = $v_html_string . "<table width='100%' border='0' cellpadding='0' cellspacing='0'><tr><td> ";
$v_html_string = $v_html_string . "<input type='hidden' name='hdn_list_xml_tag' value=''>";
$v_html_string = $v_html_string . "<input type='hidden' name='hdn_list_xml_value' value=''>";
$v_html_string = $v_html_string . "<input type='hidden' name='fuseaction' value='DISPLAY_SINGLE_CONDITIONS'>";
$v_html_string = $v_html_string . "<input type='hidden' name='hdn_recordtype_filter' value='".$v_reporttype_filter ."'>";
$v_html_string = $v_html_string . "<input type='hidden' name='hdn_recordtype' value='".$v_recordtype ."'>";
$v_html_string = $v_html_string . "<input type='hidden' name='hdn_record_id' value=''>";
$v_html_string = $v_html_string . "<input type='hidden' name='hdn_exporttype' value=''>";
$v_html_string = $v_html_string . "<input type='hidden' name='hdn_list_item_id_checked' value=''>";
$v_html_string = $v_html_string . "<input type='hidden' name='hdn_page' value='".$v_page."'>";
$v_html_string = $v_html_string . "<input type='hidden' name='hdn_record_number_page' value='".$v_limit_row."'>";

$v_html_string = $v_html_string . "</td></tr></table>";
//Bat dau bang chua tat ca cac thanh phan cua form
$v_html_string = $v_html_string . "<table width='100%'  border='0' cellspacing='0' cellpadding='0'><tr><td>";
//Bang chua cac dong cua form
$v_html_string = $v_html_string . "<table width='100%'  border='0' cellspacing='0' cellpadding='0'><tr><td> ";
///Begin///Bang chua cac dong co dinh cua ho so
$v_html_string = $v_html_string . "<table width='100%'  border='0' cellspacing='0' cellpadding='0'>";
$v_html_string = $v_html_string . "<col width='15%'><col width='85%'>";
$v_html_string = $v_html_string . "<tr><td class='small_title' align='left' colspan='5'><b>".CONST_REPORT_STEP1_LABEL."</b></td>";
$v_html_string = $v_html_string . "<tr><td class='normal_label' align='left'>".CONST_RECORDTYPE_LABEL."</td>";
$v_html_string = $v_html_string . "<td><select class='normal_selectbox' name='sel_recordtype' style='width:100%' optional='".CONST_RECORTYPE_SELECTBOX_OPTIONAL."' onChange=\"onchange_submit(this,document.forms(0).hdn_recordtype_filter,'".$fuseaction."');\">";
$v_html_string = $v_html_string . "<option id='All' name='All' value='All'";

if($v_recordtype=="All") $v_html_string = $v_html_string . " selected ";
$v_html_string = $v_html_string . ">--".CONST_RECORTYPE_SELECTBOX_LABEL."--</option>";
$v_html_string = $v_html_string . _generate_select_option($arr_single_recordtype_,'0','0','1', $v_recordtype);
$v_html_string = $v_html_string . "</select></td></tr>";
$v_html_string = $v_html_string . "</table>";
///End///Bang chua cac dong co dinh cua ho so
//Doc cac dong cua form	
$table_struct_rax = new RAX(); 
$table_struct_rec = new RAX(); 
$table_struct_rax->open($v_report_xml_string);
$table_struct_rax->record_delim = 'row';
$table_struct_rax->parse();
$table_struct_rec = $table_struct_rax->readRecord(); 
//echo htmlspecialchars($v_xml_str);
$v_html_string = $v_html_string . "</br><div  class='large_link' style='border:solid 1px #CCCCCC;width:100%'>";//dong khung phan tim kiem
while ($table_struct_rec) { 
	$table_struct_row = $table_struct_rec->getRow();
	$v_have_line_before = $table_struct_row["have_line_before"];
	$v_col_number = $table_struct_row["col_number"];
	$v_tag_list = $table_struct_row["tag_list"];
	$v_row_id = $table_struct_row["row_id"];
	$arr_tag = explode(",", $v_tag_list);
	if ($v_have_line_before=="true"){
		$v_html_string = $v_html_string . "<table width='100%'  border='0' cellspacing='0' cellpadding='0'><tr>";
		$v_html_string = $v_html_string . "<td><hr width='100%' color='#66CCFF' size='1'></td>";
		$v_html_string = $v_html_string . "</tr></table>";
	}
	//Bang chua mot dong cua form
	// dong khung tim kiem 
	$v_html_string = $v_html_string . "<table width='100%' border='0' cellspacing='0' cellpadding='0'>";
	$v_html_table = "";
	$v_html_tag = "";
	for($i=0;$i < sizeof($arr_tag);$i++){
		$formfield_rax = new RAX(); 
		$formfield_rec = new RAX(); 
		$formfield_rax->open($v_report_xml_string);
		$formfield_rax->record_delim = $arr_tag[$i];
		$formfield_rax->parse();
		$formfield_rec = $formfield_rax->readRecord(); 
		$formfield_row = $formfield_rec->getRow(); 
		$v_label = $formfield_row["label"];
		$v_type = $formfield_row["type"];
		$v_dataformat = $formfield_row["data_format"];
		$v_width = $formfield_row["width"];
		$v_row = $formfield_row["row"];
		$v_max = $formfield_row["max"];
		$v_min = $formfield_row["min"];
		$v_maxlength = $formfield_row["maxlength"];
		$v_note = $formfield_row["note"];
		$v_message = $formfield_row["message"];
		$v_optional = $formfield_row["optional"];
		$v_xml_tag_in_db = $formfield_row["xml_tag_in_db"];
		$v_js_function_list = $formfield_row["js_function_list"];
		$v_js_action_list = $formfield_row["js_action_list"];
		$v_recordtype_list = $formfield_row["recordtype_list"];
		$v_readonly_in_edit_mode = $formfield_row["readonly_in_edit_mode"];
		$v_disabled_in_edit_mode = $formfield_row["disabled_in_edit_mode"];
		if ($v_xml_str!=""){
			$column_rax = new RAX();
			$column_rec = new RAX();
			$column_rax->open($v_xml_str);
			$column_rax->record_delim = 'data_list';
			$column_rax->parse();
			$column_rec = $column_rax->readRecord(); 
			$column_row = $column_rec->getRow();
			$v_value = _restore_XML_bad_char($column_row[$v_xml_tag_in_db]); 			
		}
		if ($v_type=="selectbox"){
			$v_selectbox_option_sql = $formfield_row["selectbox_option_sql"];
			$v_selectbox_id_column = $formfield_row["selectbox_option_id_column"];
			$v_selectbox_name_column = $formfield_row["selectbox_option_name_column"];
		}
		if ($v_type=="checkboxmultiple"){
			$v_checkbox_multiple_sql = $formfield_row["checkbox_multiple_sql"];
			$v_checkbox_multiple_id_column = $formfield_row["checkbox_multiple_id_column"];
			$v_checkbox_multiple_name_column = $formfield_row["checkbox_multiple_name_column"];
		}
		
		$v_html_table = $v_html_table . "<col width='$v_first_col_width'>" . "<col width='$v_second_col_width'>";		
		$v_html_tag = $v_html_tag . Generate_HTML_Input();		
		//echo $v_recordtype_list.'<br/>'; 
		
		//============== Bo sung tim kiem DatCQ
		$arr_recordtype_list = explode(",",$v_recordtype_list);
		$style = '';
		//echo $v_recordtype;
		
		if( $v_recordtype == "All"){
			if($arr_tag[$i]=='dai_dien_a' || $arr_tag[$i]=='dai_dien_b'){
				$style = "display:none";
			}else{
			$style = "display:block";
		}
			
		}else{
			if( $v_recordtype_list == "All"){
				$style = "display:block";
			}else{
				if(in_array($v_recordtype,$arr_recordtype_list)){
					$style = "display:block";	
				}
				else
					$style = "display:none";
			}
		}
		//============== Bo sung tim kiem DatCQ
	}
	$v_html_string = $v_html_string .  $v_html_table . "<tr id = '$v_row_id' style='".$style."'>" . "<td class='normal_label'>" . $v_html_tag."</td>";
	$v_html_string = $v_html_string . "</tr></table>";
	$table_struct_rec = $table_struct_rax->readRecord();
}
$v_html_string = $v_html_string . "</td></tr></table></div>";
//End//Bang chua cac thanh phan cua form
echo $v_html_string;
?>
<table width='100%'  border='0' cellspacing='0' cellpadding='0'>
	<tr>
	  <td>&nbsp;</td>
  </tr>
	<tr>
	  <td align='center'><input type='button' style="width:100px" class='normal_button' name="btn_search" value='<?php echo CONST_OUTPUT_BUTTON;?>' onclick="check_value_in_form();" onkeydown="change_focus(document.forms(0),this)" />
	  <input type='button' class='normal_button' style="width:150px" name="btn_clear" value='<?php echo CONST_CLEAR_BUTTON;?>' onclick="clear_all();"/></td>
  </tr>
	<tr>
	  <td align='center'>&nbsp;</td>
  </tr>
</table>
	</td>
	</tr>
</table>
<script language="javascript">
document.forms(0).dai_dien_a.value='<? echo $dai_dien_a;?>';
document.forms(0).dai_dien_b.value='<? echo $dai_dien_b;?>';
</script>
<!--Ket thuc bang chinh-->
<!--//End//Form<form>-->